package com.xxg.renrenmessage.service;

import com.xxg.renrencommon.domain.bean.MessageInfo;
import com.xxg.renrencommon.domain.result.BaseResult;
import com.xxg.renrenmessage.dao.MessageInfoDao;
import com.xxg.renrenmessage.domain.query.ListMessageQuery;
import com.xxg.renrenmessage.domain.query.SetAllReadQuery;
import com.xxg.renrenmessage.domain.query.SetReadQuery;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 类说明
 *
 * @author szj
 * @date 2021/12/6
 */
@Service
@Slf4j
@AllArgsConstructor
public class MessageServiceImpl implements MessageService{
    private final MessageInfoDao messageInfoDao;

    @Override
    public BaseResult<List<MessageInfo>> list(String userId, ListMessageQuery query) {
        List<MessageInfo> messageInfos = messageInfoDao.findByRecipientIdAndType(Integer.parseInt(userId), query.getType(), query.getPageNo(), query.getPageSize());
        return new BaseResult<>(messageInfos);
    }

    @Override
    public BaseResult<Void> setRead(String userId, SetReadQuery query) {
        messageInfoDao.setReadByIds(Integer.parseInt(userId), query.getIds());
        return new BaseResult<>();
    }

    @Override
    public BaseResult<Void> setAllRead(String userId, SetAllReadQuery query) {
        messageInfoDao.setAllReadByType(Integer.parseInt(userId), query.getType());
        return new BaseResult<>();
    }

    @Override
    public BaseResult<Void> delete(String userId, SetReadQuery query) {
        messageInfoDao.deleteByIds(Integer.parseInt(userId), query.getIds());
        return new BaseResult<>();
    }
}
